<template>
  <div>
    <h3>修改订单</h3>
    <el-form id="myform" ref="form" :model="order" label-width="80px">
      <el-form-item label="订单编号">
        <el-input v-model="order._id" disabled></el-input>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-input v-model="order.orderTime" disabled></el-input>
      </el-form-item>
      <el-form-item label="联系方式">
        <el-input v-model="order.userId.phone"></el-input>
      </el-form-item>
      <el-form-item label="收货地址">
        <el-input v-model="order.shippingAddress"></el-input>
      </el-form-item>
      <el-form-item label="购买数量">
        <el-input v-model="order.numbers"></el-input>
      </el-form-item>

      <el-form-item label="订单状态">
        <el-select v-model="order.bool">
          <el-option label="交易中" value="1"></el-option>
          <el-option label="取消交易" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      order: {
        _id: "", //订单id
        userId: "", //保存买家联系方式
        commodityId: "", //商品id
        numbers: "", //商品数量
        shippingAddress: "", //收货地址
        totalPrices: "", //商品总价
        actualPayment: "", //买家实付款
        orderTime: "", //订单创建时间
        //receivingDingesteds:'2020-02-24',
        bool: "" //订单状态 1：交易中 2：取消交易
      }
    };
  },
  async created() {
    let _id = this.$route.params;
    let { data } = await axios.post("/orders/getOneOrder", { _id });
    this.order = data[0];
    //console.log(this.order);
  },
  methods: {
    onSubmit() {
      this.updateOrders();
    },
    //弹框提示
    open() {
      this.$alert("修改成功", {
        confirmButtonText: "确定",
        callback: action => {
          this.$message({
            type: "info",
            message: `action: ${action}`
          });
          this.$router.push('/admin/index/orders');
        }
      });
    },
    async updateOrders() {
      let { data } = await axios.post("/orders/updateOrders", this.order);
      //console.log(data);
      if (data) {
        this.open();
      }
    }
  }
};
</script>

<style>
h3{
  margin-left: 0;
}
.el-form {
  margin: 30px auto 0;
  padding: 10px;
  width: 50%;
  border: 2px solid blue;
  font-weight: bold;
}
</style>